package com.example.administrator.testproject.flagTextview;

import android.content.Context;
import android.graphics.Color;
import android.support.v7.widget.RecyclerView;
import android.util.Log;
import android.view.Gravity;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.TextView;

import com.example.administrator.testproject.R;

import java.util.List;

/**
 * Created by shengfh on 2018/1/15.
 */

public class FlagAdapter extends BaseAdapter {
    private Context mContext;
    private List<String> data;

    public FlagAdapter(Context mContext, List<String> data) {
        this.mContext = mContext;
        this.data = data;
    }

//    @Override
//    public ViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
//        return new ViewHolder(LayoutInflater.from(mContext).inflate(R.layout.item_flag,null));
//    }
//
//    @Override
//    public void onBindViewHolder(ViewHolder holder, int position) {
//        holder.flagTextView.addFlagText("大学",R.drawable.shape_text_flag, Color.BLUE, Gravity.LEFT);
//        holder.flagTextView.addFlagText("奥数赛",R.drawable.shape_text_flag,Color.BLACK,Gravity.LEFT);
////        flagText.addFlagDrawable(R.mipmap.ic_auth,Gravity.RIGHT);
////        flagText.addFlagDrawable(R.mipmap.ic_auth,Gravity.RIGHT);
//        holder.flagTextView.setContentText(data.get(position));
//        holder.textView.setText("11111");
////        holder.layout.requestLayout();
//    }

    @Override
    public int getCount() {
        return data.size();
    }

    @Override
    public Object getItem(int position) {
        return data.get(position);
    }

    @Override
    public long getItemId(int position) {
        return position;
    }


    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
        ViewHolder holder = null;
        if (convertView == null) {
            convertView = LayoutInflater.from(mContext).inflate(R.layout.item_flag, null);
            holder = new ViewHolder(convertView);
            convertView.setTag(holder);
        }
        holder = (ViewHolder) convertView.getTag();
//        holder.flagTextView.setMaxLine(position+1);
        holder.flagTextView2.addFlagText("大学", R.drawable.shape_text_flag, Color.BLUE, Gravity.LEFT);
        holder.flagTextView2.addFlagText("奥数赛", R.drawable.shape_text_flag, Color.BLACK, Gravity.LEFT);
        if (position == 0) {
            holder.tagText.builder()
                    .setContentText("奥数赛 大学 世纪东方就爱上了大姐夫阿斯蒂芬啥都打发的发生的打法阿斯蒂芬啊啊是的发送到")
                    .build();
        } else {
            holder.tagText.builder().addFlagText("奥数赛", Color.BLACK, false, Gravity.LEFT)
                    .addFlagText("大学", Color.BLUE, true, Gravity.LEFT)
                    .addFlagDrawable(R.mipmap.ic_auth, Gravity.RIGHT)
                    .addFlagDrawable(R.mipmap.ic_auth, Gravity.RIGHT)
                    .addFlagColorText(Color.GREEN, "[稀缺]", Gravity.LEFT)
                    .setContentText(data.get(position))
                    .build();
        }

        Log.e("Tag", position + "");
//        holder.flagTextView2.addFlagDrawable(R.mipmap.ic_auth,Gravity.RIGHT);
//        flagText.addFlagDrawable(R.mipmap.ic_auth,Gravity.RIGHT);
        holder.flagTextView2.setContentText(data.get(position));
//        holder.flagTextView2.setContentText(data.get(position));
        holder.textView.setText("11111");
//        holder.layout.requestLayout();
        return convertView;
    }

    class ViewHolder extends RecyclerView.ViewHolder {
        private final TagTextView tagText;
        FlagTextView flagTextView;
        FlagTextView2 flagTextView2;
        TextView textView;

        //        LinearLayout layout;
        public ViewHolder(View convertView) {
            super(convertView);
            textView = convertView.findViewById(R.id.testView);
            flagTextView = (FlagTextView) convertView.findViewById(R.id.flag_text);
            flagTextView2 = (FlagTextView2) convertView.findViewById(R.id.flag_text2);
            tagText = (TagTextView) convertView.findViewById(R.id.tag_text);
//            layout=convertView.findViewById(R.id.layout);
        }
    }
}
